<template>
  <section class="my-parttime">
    <div class="item" v-for="item in list" :key="item">
      <div class="top" @click="routerTo('/pages/my/parttimedetail/main',item,1)">
        <div class="flex flex-between flex-middle">
          <div class="title">{{item.job_name}}</div>
          <div class="status" v-if="item.job_apply_status==1">已报名</div>
          <div class="status" v-else-if="item.job_apply_status==2">已查看</div>
          <div class="status" v-else-if="item.job_apply_status==3">已取消</div>
          <div class="status" v-else-if="item.job_apply_status==4">已录用</div>
          <div class="status" v-else-if="item.job_apply_status==5">已到岗</div>
          <div class="status" v-else-if="item.job_apply_status==6">已结算</div>
            <div class="status" v-else-if="item.job_apply_status==7">待录用</div>
        </div>
        <div
          class="desc mt15"
        >{{item.area_name}} | {{item.settlement==1?'小时':''}}{{item.settlement==2?'日结':''}}{{item.settlement==3?'周结':''}}{{item.settlement==4?'月结':''}} | {{item.create_time}} | {{item.settlement=='1'?item.salary+'元/小时':item.settlement=='2'?item.salary+'元/日':item.settlement=='3'?item.salary+'元/周':item.settlement=='3'?item.salary+'元/月':''}}</div>
      </div>
      <div class="flex bottom flex-main-end">
        <button
          class="giveup"
          @click="cancelJobsApply(item.id)"
          v-if="item.job_apply_status==1"
        >放弃报名</button>
        <button class="link" @click.stop="phoneCall(item.link_tel)">联系企业</button>
        <button class="del" v-if="item.job_apply_status==3 || item.job_apply_status==6" @click="deleteJobsApply(item.id)">删除</button>
      </div>
    </div>
  </section>
</template>
<script>
export default {
  data() {
    return {
      id: "",
      list: ""
    };
  },
  onShow() {
    this.getJobsList();
  },
  methods: {
    getJobsList() {
      this.$api.getJobsList().then(res => {
        this.list = res.data.myJobsList.map(item => {
          item.create_time = this.formatDate(item.create_time);
          return item;
        });
      });
    },
    routerTo(url, item, type) {
      if (item.job_apply_status == 3) {
          wx.showToast({
              title: "暂无兼职进度", //提示的内容,
              icon: "none", //图标,
              duration: 1500, //延迟时间,
              mask: true //显示透明蒙层，防止触摸穿透,
          });
        return;
      }
      wx.navigateTo({ 'url':url+'?id='+item.id+'&type='+type });
    },
    phoneCall(phoneNumber) {
      wx.makePhoneCall({
        phoneNumber //仅为示例，并非真实的电话号码
      });
    },
    //取消兼职申请
    cancelJobsApply(id) {
      const self = this;
      wx.showModal({
        title: '取消',
        content: '您确定要取消兼职申请？',
        success(res) {
          if (res.confirm) {
            self.$api.cancelJobsApply({ id }).then(res => {
              if (res.code == 0) {
                wx.showToast({
                  title: res.msg, //提示的内容,
                  icon: "none", //图标,
                  duration: 1500, //延迟时间,
                  mask: true, //显示透明蒙层，防止触摸穿透,
                  success: res => {
                    self.getJobsList();
                  }
                });
              } else {
                wx.showToast({
                  title: res.msg, //提示的内容,
                  icon: "none", //图标,
                  duration: 1500, //延迟时间,
                  mask: true //显示透明蒙层，防止触摸穿透,
                });
              }
            });
          } else if (res.cancel) {
          }
        }
      })
    },
    //删除兼职申请
    deleteJobsApply(id) {
      const self = this;
      wx.showModal({
        title: '删除',
        content: '您确定要删除兼职申请？',
        success(res) {
          if (res.confirm) {
            self.$api.deleteJobsApply({ id }).then(res => {
            if (res.code == 0) {
              wx.showToast({
                title: res.msg, //提示的内容,
                icon: "none", //图标,
                duration: 1500, //延迟时间,
                mask: true, //显示透明蒙层，防止触摸穿透,
                success: res => {
                  self.getJobsList();
                }
              });
            } else {
              wx.showToast({
                title: res.msg, //提示的内容,
                icon: "none", //图标,
                duration: 1500, //延迟时间,
                mask: true, //显示透明蒙层，防止触摸穿透,
                success: res => {}
              });
            }
          });
          } else if (res.cancel) {
          }
        }
      })
    }
  }
};
</script>
<style lang="scss" scoped>
.my-parttime {
  .item {
    margin: 15px;
    background: white;
    padding: 0 15px;
    border-radius: 4px;
    .top {
      padding: 15px 0;
      border-bottom: 1px solid #ededed;
    }
    .bottom {
      padding: 15px 0;
      & > button:not(:last-child) {
        margin-right: 15px;
      }
    }
    .title {
      font-size: 15px;
      font-family: PingFang;
      font-weight: 500;
      color: rgba(46, 46, 46, 1);
    }
    .status {
      font-size: 14px;
      font-family: PingFang;
      font-weight: 500;
      color: rgba(59, 184, 253, 1);
    }
    .desc {
      font-size: 12px;
      font-family: PingFang;
      font-weight: 500;
      color: rgba(193, 196, 201, 1);
    }
    button {
      width: 60px;
      height: 21px;
      background: rgba(59, 184, 253, 1);
      border-radius: 2px;
      font-size: 12px;
      font-family: PingFang;
      font-weight: 500;
      line-height: 21px;
      margin: 0;
      padding: 0;
    }
    .giveup {
      border: 1px solid rgba(59, 184, 253, 1);
      background: white;
      color: rgba(59, 184, 253, 1);
    }
    .link,
    .del {
      color: rgba(255, 255, 255, 1);
    }
  }
}
</style>
<style lang="scss">
page {
  background: #f7f7f7;
}
</style>
